package com.ego.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ego.item.entity.Brand;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BrandMapper extends BaseMapper<Brand> {
    /**
     * 新增商品分类和品牌中间表数据
     *
     * @param cid 中间表种类的cid
     * @param id    中间表品牌的id
     * @return
     */
    @Insert("Insert into tb_category_brand(category_id,brand_id) values (#{cid},#{id})")
    int insertCategoryAndBrand(@Param("cid")Long cid, @Param("id")Long id);

    /**
     * 根据id删除中间表相关联表
     * @param id
     * @return
     */
    @Delete("Delete from tb_category_brand where brand_id=#{id}")
    int deleteCategoryAndBrand( @Param("id")Long id);

    @Delete("Delete from tb_brand where id=#{id}")
    int deleteBrand( @Param("id")Long id);

    @Select("select * from tb_brand where id in(select brand_id from  tb_category_brand where category_id = #{cid})")
    List<Brand> selectListByCid(@Param("cid") Integer cid);
}
